<?php

namespace Yolo\Errors;

class RpcApiError
{
    protected string $module = 'rpc_api';

    protected string $type = 'system';

    protected int $code = 0xFFFFFFFF;

    protected string $symbol = 'system_error';

    protected string $message = 'System error.';

    protected int $httpStatus = 500;

    protected array $metadata = [];

    public function setHttpStatus(int $httpStatus): static
    {
        $this->httpStatus = $httpStatus;
        return $this;
    }

    public function setMetadata(array $metadata): static
    {
        $this->metadata = $metadata;
        return $this;
    }

    /**
     * @return string
     */
    public function getModule(): string
    {
        return $this->module;
    }

    /**
     * @return string
     */
    public function getType(): string
    {
        return $this->type;
    }

    /**
     * @return string
     */
    public function getSymbol(): string
    {
        return $this->symbol;
    }

    /**
     * @return string
     */
    public function getMessage(): string
    {
        return $this->message;
    }

    /**
     * @return int
     */
    public function getHttpStatus(): int
    {
        return $this->httpStatus;
    }

    /**
     * @return array
     */
    public function getMetadata(): array
    {
        return $this->metadata;
    }

    public function getCode(): int
    {
        return $this->code;
    }

    public function toRpcResponse(): array
    {
        return [
            'module' => $this->module,
            'type' => $this->type,
            'code' => $this->code,
            'symbol' => $this->symbol,
            'message' => $this->message,
            'metadata' => $this->metadata,
            'http' => [
                'statusCode' => $this->httpStatus,
            ],
        ];
    }
}